<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"EX-1");
$currentPage = $_SERVER["PHP_SELF"];

mysql_select_db($database_con_gl, $con_gl);
$query_l_kel = "SELECT id, gudang FROM gl_gudang ORDER BY gudang ASC";
$l_kel = mysql_query($query_l_kel, $con_gl) or die(mysql_error());
$row_l_kel = mysql_fetch_assoc($l_kel);
$totalRows_l_kel = mysql_num_rows($l_kel);

$maxRows_data = 8;
$pageNum_data = 0;
if (isset($_GET['pageNum_data'])) {
  $pageNum_data = $_GET['pageNum_data'];
}
$startRow_data = $pageNum_data * $maxRows_data;
$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);
mysql_select_db($database_con_gl, $con_gl);
$query_data = "SELECT gl_transaksimutasi.id, gl_transaksimutasi.tgltransaksi,  gl_transaksimutasi.tglefektif, gl_masterkendaraan.nopolisi, gl_merkkendaraan.merk, gl_tipekendaraan.tipekendaraan, (select gl_gudang.gudang from gl_gudang where gl_gudang.id = gl_transaksimutasi.cabangasal) as cabangasal,gl_gudang.gudang,gl_transaksimutasi.created_by FROM gl_transaksimutasi, gl_masterkendaraan, gl_merkkendaraan, gl_tipekendaraan, gl_gudang WHERE gl_masterkendaraan.id = gl_transaksimutasi.nopolisi AND gl_merkkendaraan.id = gl_masterkendaraan.merk AND gl_tipekendaraan.id = gl_masterkendaraan.tipekendaraan AND gl_gudang.id = gl_transaksimutasi.kecabang";
if(isset($_GET[cr_txt]) AND $_GET[cr_txt]<>'' AND $_GET[cr_txt]<>'+') { 
$decode_cr = str_replace("+"," ",$_GET[cr_txt]);
$query_data .=" AND (gl_transaksimutasi.nopolisi LIKE '%%$decode_cr%%' OR gl_merkkendaraan.merk LIKE '%%$decode_cr%%' OR gl_tipekendaraan.tipekendaraan LIKE '%%$decode_cr%%')";
}
if(isset($_GET[cr_kel]) AND $_GET[cr_kel]<>'ALL') { 
$query_data .=" AND gl_transaksimutasi.cabangasal ='$_GET[cr_kel]'";
}
$query_data .=" ORDER BY gl_transaksimutasi.nopolisi";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRows_data = mysql_num_rows($data);
$totalPages_data = floor($totalRows_data / $maxRows_data);
$query_data .=" LIMIT $startRow_data, $maxRows_data";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRow_data = mysql_num_rows($data);
$row_data = mysql_fetch_assoc($data);

$queryString_data = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_data") == false && 
        stristr($param, "totalRows_data") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_data = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);
include('include/widget_exportdata.php');
?>
<h1>Daftar Transaksi Mutasi</h1>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 
  <tr valign="top" bgcolor="#FFFFFF" class="hide">
        <td><?php if(strstr($_SESSION[akses],"EX-1-1")) { ?><a href="index.php?component=transaksimutasi&task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>
        <td colspan="7" align="right" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><form id="search" name="search" method="post" action="">
      <label>
      <select name="cr_kel" id="cr_kel" onchange="cr_txt.value=''">
        <option value="ALL" <?php if (!(strcmp("ALL", $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>>Pilih Cabang</option>
        <?php
do {  
?>
        <option value="<?php echo $row_l_kel['id']?>"<?php if (!(strcmp($row_l_kel['id'], $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>><?php echo $row_l_kel['gudang']?></option>
        <?php
} while ($row_l_kel = mysql_fetch_assoc($l_kel));
  $rows = mysql_num_rows($l_kel);
  if($rows > 0) {
      mysql_data_seek($l_kel, 0);
	  $row_l_kel = mysql_fetch_assoc($l_kel);
  }
?>
      </select>
      </label>
<label>
      <input name="cr_txt" type="text" id="cr_txt" value="find By: no.polisi, no.ref, merk, tipe"; onclick="this.value='';" "<?php echo $_REQUEST['cr_txt'];?>" size="40" maxlength="100" />
      </label>
      <label>
      <input name="Search" type="submit" id="Search" value="Search" />
      </label>
    </form>
	<?php
	if(isset($_POST['Search'])) {
		echo "<script>window.location=\"index.php?component=transaksimutasi&cr_kel=".$_POST[cr_kel]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";
	}
	?></td>
  </tr>
  <tr>
    <th width="121"><strong>No. Polisi</strong></th>
    <th width="107">Merk</th>
    <th width="297">Tipe</th>
    <th width="113">Tgl Transaksi </th>
    <th width="144"><strong>Tgl Efektif</strong></th>
    <th width="131">Cabang Asal </th>
    <th width="131">Mutasi ke Cabang </th>
    <th width="131">Dimutasi oleh </th>
    <th width="184" align="center" class="hide"><strong>Aksi</strong></th>
  </tr>
  <?php if($totalRows_data > 0) { ?>
  <?php do { ?>
    <tr valign="top" bgcolor="#FFFFFF">
      <td><?php echo $row_data['nopolisi']; ?></td>
      <td><?php echo $row_data['merk']; ?></td>
      <td><?php echo $row_data['tipekendaraan']; ?></td>
      <td><?php echo $row_data['tgltransaksi']; ?></td>
      <td><?php echo $row_data['tglefektif']; ?></td>
      <td><?php echo $row_data['cabangasal']; ?></td>
      <td><?php echo $row_data['gudang']; ?></td>
      <td><?php echo $row_data['created_by']; ?></td>
      <td align="center" class="hide"><?php if(strstr($_SESSION[akses],"EX-1-2")) { ?><a href="index.php?component=transaksimutasi&amp;task=edit&amp;id=<?php echo $row_data['id']; ?>"><img src="images/edit_.png" border="0"/></a><?php } ?> <?php if(strstr($_SESSION[akses],"EX-1-3")) { ?><?php } ?></td>
    </tr>
    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="10"><table border="0" align="left" width="50%">
          <tr>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0 ></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
			<td width="88%">Halaman : <?php echo $pageNum_data+1; ?>, Ditampilkan <?php echo $totalRow_data; ?> dari <?php echo $totalRows_data; ?> total data</td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>
  <tr bgcolor="#FFFFFF">
    <td colspan="8">Data tidak ada !!! </td>
  </tr>
  <?php } ?>
  <tr class="hide">
    <td colspan="8"><?php if(strstr($_SESSION[akses],"EX-1-1")) { ?><a href="index.php?component=transaksimutasi&task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>
  </tr>
</table>


<?php
mysql_free_result($data);

mysql_free_result($l_kel);
?>
